/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.hft_stuttgart.botwar.database;

import java.io.Serializable;
import java.util.Calendar;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;

/**
 *
 * @author pmv-mail@gmx.de
 */
@Entity
@Table(name="tblStat")
public class Statistic implements Serializable {
    @Id
    private String playername;
    @Column(nullable=false)
    private long experience;
    @Column(nullable=false)
    private int wonMatches;
    @Column(nullable=false)
    private int lostMatches;
    @Column(nullable=false)
    private int drawMatches;
    @Column(nullable=false)
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Calendar lastOnlineTime;
    @Column(nullable=false)
    private long playingTime;
    @Column(nullable=false)
    private long onlineTime;

    /**
     * This constructor just exists because of the requirements of jpa.
     * Please do not use.
     * @deprecated
     */
    @Deprecated
    public Statistic() {
    }

    /**
     * Used in playerconstructor for creating a new empty statistic.
     * @param player the player of this statistic
     */
    public Statistic(final Player player) {
        this.playername = player.getUsername();
        this.experience = 0;
        this.wonMatches = 0;
        this.lostMatches = 0;
        this.drawMatches = 0;
        this.lastOnlineTime = Calendar.getInstance();
        this.playingTime = 0;
        this.onlineTime = 0;
    }

    /**
     *
     * @param ranking ranking of this statistic
     * @param player player of this statistic
     * @param exp experience of this statistic
     * @param wonMatches won matches of this statistic
     * @param lostMatches lost matches of this player statistic
     * @param drawMatches draw matches of this player statistic
     * @param lastOnlineTime last online time of this player statistic
     * @param playingTime whole playing time of this player statistic
     * @param onlineTime whole online time of this player statistic
     */
    public Statistic(final int ranking,
                     final Player player,
                     final long exp,
                     final int wonMatches,
                     final int lostMatches,
                     final int drawMatches,
                     final Calendar lastOnlineTime,
                     final long playingTime,
                     final long onlineTime) {
        this.playername = player.getUsername();
        this.experience = exp;
        this.wonMatches = wonMatches;
        this.lostMatches = lostMatches;
        this.drawMatches = drawMatches;
        this.lastOnlineTime = lastOnlineTime;
        this.playingTime = playingTime;
        this.onlineTime = onlineTime;
    }

    /**
     *
     * @return name of the player from this statistic
     */
    public String getPlayername(){
        return playername;
    }

    /**
     *
     * @return experience points of the player from this statistic
     */
    public long getExperience() {
        return experience;
    }

    /**
     *
     * @param exp experience points to be add to the player from this statistic
     */
    public void addExperience(final long exp) {
        this.experience += exp;
    }

    /**
     *
     * @return draw matches of the player from this statistic
     */
    public int getDrawMatches() {
        return drawMatches;
    }

    /**
     * addes one draw match to the player from this statistic
     */
    public void addDrawMatches() {
        this.drawMatches++;
    }

    /**
     *
     * @return lost matches of the player from this statistic
     */
    public int getLostMatches() {
        return lostMatches;
    }

    /**
     * addes one lost match to the player from this statistic
     */
    public void addLostMatches() {
        this.lostMatches++;
    }

    /**
     *
     * @return won matches of the player from this statistic
     */
    public int getWonMatches() {
        return wonMatches;
    }

    /**
     * addes one won match to the player from this statistic
     */
    public void addWonMatches() {
        this.wonMatches++;
    }

    /**
     *
     * @return last online time and date of the player from this statistic
     */
    public Calendar getLastOnlineTime(){
        return lastOnlineTime;
    }

    /**
     *
     * @return last online time of the player from this statistic
     */
    public long getOnlineTime() {
        return onlineTime;
    }

    /**
     *
     * @return playint time of the player from this statistic
     */
    public long getPlayingTime() {
        return playingTime;
    }

    /**
     *
     * @param lastOnlineTime last online time and date
     * of the player from this statistic
     */
    public void setLastOnlineTime(final Calendar lastOnlineTime) {
        this.lastOnlineTime = lastOnlineTime;
    }

    /**
     *
     * @param onlineTime online time to be add to the player from this statistic
     */
    public void addOnlineTime(final long onlineTime) {
        this.onlineTime += onlineTime;
    }

    /**
     *
     * @param playingTime playint time to be add
     * to the player from this statistic
     */
    public void addPlayingTime(final long playingTime) {
        this.playingTime += playingTime;
    }
}
